<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>noteinfo</title>
</head>
<body>
    <p title="xinwen">新闻</p>
    <script>
        var p = document.querySelector('p');
        // 元素节点
       console.log(p.nodeName);
       console.log(p.nodeType);
       console.log(p.nodeValue)
        // 属性节点
       var ps = p.attributes[0];
       console.log(ps.nodeName);
       console.log(ps.nodeType);
       console.log(ps.nodeValue);
        // 文本节点
        var pn =p.childNodes[0];
        console.log(pn.nodeName);
        console.log(pn.nodeType);
        console.log(pn.nodeValue);

        // 去除空白节点
       function clear(element){
           for(var i=0;i<element.childNodes.length;i++){
               var node = element.childNodes[i];
               if(node.nodeType==3&&!/\S/.test(node.nodeValue)){
                   node.parentNode.removeChild(node);
               }
           }
       }
       var html = document.childNodes[1];
       console.log(html.childNodes);
       clear(html);
       console.log(html.childNodes);
        // 节点操作
       var body = html.childNodes[1];
       console.log(body.childNodes);
       var script = body.childNodes[3];
       //创建table
       var table =document.createElement('table');
       for(var row=0;row<3;row++){
           var tr = document.createElement('tr');
           for(var col=0;col<4;col++){
               var td = document.createElement('td');
               var tdv = document.createTextNode('第'+row+'行第'+col+'列');
               td.appendChild(tdv);
               tr.appendChild(td);
           }
           table.appendChild(tr);
       }
        // body.appendChild(table);//等价于
        body.insertBefore(table,script);
    </script>

</body>
</html>